<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>js onunload() event</title>
</head>
<body onunload="tip()">

    <script type="text/javascript">
        function tip() {
            alert("用户 is leaving!");
        }
    </script>
</body>
</html>